|
RAIS
3.2
|
00001 using System; 00002 using System.Collections.Generic; 00003 using System.Text; 00004 using System.Data; 00005 00006 namespace RAIS.Common 00007 { 00008 public class SealedSource 00009 { 00010 #region Constants 00011 private const string REGNOMBER_FIELD_NAME = "Regulatory Authority Source No"; 00012 private const string ONE_NUCLIDE_FIELD_NAME = "One Nuclide"; 00013 private const string ISOTOPE_FIELD_NAME = "FirstOfIsotope"; 00014 private const string HALF_LIFE_FIELD_NAME = "FirstOfHalf Life"; 00015 private const string FACTOR_FIELD_NAME = "FirstOfFactor"; 00016 private const string ACTIVITY_DATE_FIELD_NAME = "Activity Date"; 00017 private const string ACTIVITY_FIELD_NAME = "Activity"; 00018 private const string INTERVAL_FIELD_NAME = "Interval"; 00019 private const string NAME_FIELD_NAME = "Name"; 00020 00021 private const string NO_NUCLIDE_MESSAGE = "Source does not have a single nuclide. May not compute"; 00022 private const string NO_HALFLIFE_MESSAGE = "Halflife of nuclide {0} is unknown. May not compute"; 00023 private const string NO_DATE_MESSAGE = "Unknown Sealed Source Activity or Date. May not compute"; 00024 #endregion 00025 00026 #region Fields 00027 string name; 00028 double halfLife; 00029 double factor; 00030 DateTime activityDateField; 00031 double activityField; 00032 00033 string nuclide; 00034 string activityDate; 00035 string activity; 00036 string calculationActivity; 00037 string regNumber; 00038 DateTime calculationDate; 00039 #endregion 00040 00041 #region Properties 00042 00043 00044 00045 public string RegNumber { get { return regNumber; } } 00049 public DateTime CalculationDate 00050 { 00051 get { return calculationDate; } 00052 set 00053 { 00054 calculationDate = value; 00055 calculationActivity = CalculateActivity(); 00056 } 00057 } 00061 public string CalculationActivity { get { return calculationActivity; } } 00065 public string Nuclide { get { return nuclide; } } 00069 public string ActivityDate { get { return activityDate; } } 00073 public string Activity { get { return activity; } } 00074 #endregion 00075 00076 #region Private methods 00077 00078 private void Init(IDataReader reader, DateTime calculation) 00079 { 00080 regNumber = (string)reader[REGNOMBER_FIELD_NAME]; 00081 CalculationDate = calculation; 00082 int oneNuclide = (int)reader[ONE_NUCLIDE_FIELD_NAME]; 00083 string firstOfIsotope; 00084 string interval; 00085 00086 if (oneNuclide != 1 || reader[ISOTOPE_FIELD_NAME] is DBNull) 00087 { 00088 nuclide = NO_NUCLIDE_MESSAGE; 00089 return; 00090 } 00091 00092 firstOfIsotope = (string)reader[ISOTOPE_FIELD_NAME]; 00093 if (reader[HALF_LIFE_FIELD_NAME] is DBNull || reader[FACTOR_FIELD_NAME] is DBNull) 00094 { 00095 nuclide = string.Format(NO_HALFLIFE_MESSAGE, firstOfIsotope); 00096 return; 00097 } 00098 factor = (double)reader[FACTOR_FIELD_NAME]; 00099 halfLife = (double)reader[HALF_LIFE_FIELD_NAME]; 00100 interval = reader[INTERVAL_FIELD_NAME] is DBNull ? "" : (string)reader[INTERVAL_FIELD_NAME]; 00101 nuclide = firstOfIsotope + ", having a halflife of " + halfLife + " " + interval + "(s)"; 00102 if (reader[ACTIVITY_DATE_FIELD_NAME] is DBNull || reader[ACTIVITY_FIELD_NAME] is DBNull) 00103 { 00104 activityDate = NO_DATE_MESSAGE; 00105 return; 00106 } 00107 activityDateField = (DateTime)reader[ACTIVITY_DATE_FIELD_NAME]; 00108 00109 activityField = (double)reader[ACTIVITY_FIELD_NAME]; 00110 name = reader[NAME_FIELD_NAME] is DBNull ? "" : (string)reader[NAME_FIELD_NAME]; 00111 00112 activityDate = activityDateField.Date.ToString("dd.MM.yyyy"); 00113 activity = activityField.ToString("E2") + " " + name; 00114 calculationActivity = CalculateActivity(); 00115 } 00116 private string CalculateActivity() 00117 { 00118 double result; 00119 if (factor * halfLife == 0) 00120 result = 0; 00121 else 00122 { 00123 double timeStamp = (CalculationDate.Date - activityDateField).TotalSeconds; 00124 double extent = timeStamp / (halfLife * factor); 00125 result = activityField * Math.Pow(2, -extent); 00126 } 00127 return result.ToString("E2") + " " + name; 00128 } 00129 #endregion 00130 00131 00132 00133 00134 00135 public SealedSource(IDataReader reader, DateTime calculation) 00136 { 00137 Init(reader, calculation); 00138 } 00142 public SealedSource() { calculationDate = DateTime.Now; regNumber = ""; } 00143 } 00144 }